#pragma once


#include <IXMsgBox.h>
#include "XWindowImpl.h"

#include <IXLabel.h>
#include <IXImage.h>
#include <IXButton.h>

#include <map>
#include <vector>

struct stButtonData
{
    UINT        uId;
    XString     strText;
    XString     strTextResId;
    IXButton*   pBtn;
};
typedef std::vector<stButtonData>           ButtonDataVector;

enum
{
    ICON_INDEX_Error,
    ICON_INDEX_Question,
    ICON_INDEX_Warning,
    ICON_INDEX_Information,
};

template <class I, class WndBase>
class CXMsgBoxImpl : public CXWindowImpl<I, WndBase>, public CXEventHandler<CXMsgBoxImpl<I, WndBase>>
{
    typedef CXWindowImpl<I, WndBase> superclass;
    typedef CXEventHandler<CXMsgBoxImpl<I, WndBase>> eventhelper;

    BEGIN_DEF_SKIN_CLASS(CXMsgBox, superclass, gs_strGuidXSkin)
        IMP_BASIC_INTF(IXMsgBox,    0)
    END_DEF_SKIN_CLASS();

    IMPL_CONTROL_OBJ(CXMsgBoxImpl, superclass, _T("MsgBox"));

public:
    CXMsgBoxImpl();
    virtual ~CXMsgBoxImpl();

public:
    // IXMsgBox
    virtual void    STDMETHODCALLTYPE   SetButtonText(UINT uButtonId, LPCTSTR szBtnText);
    virtual void    STDMETHODCALLTYPE   SetMsgBoxParam(LPCTSTR szCaption, LPCTSTR szText, UINT uFlags);

protected:
    // CXControlImpl
    virtual void OnCreate();
    virtual HRESULT OnSkinLangChanged();

    // CXMsgBoxImpl
    void    PrepareButtonId();
    void    InitBkg();
    void    CreateControls();
    void    Beep();
    void    CalcSize(SIZE* pSize);


    // Event
    void    OnButtonClicked(IXControl* pSrcControl, LPARAM lParam);

protected:
    XString             m_strCaption;
    XString             m_strText;
    XString             m_strCaptionResId;
    XString             m_strTextResId;

    int                 m_nIconIndex;

    UINT                m_uFlags;

    typedef std::map<int, XString>  ButtonTextMap;
    ButtonTextMap       m_ButtonTextMap;

    ButtonDataVector    m_vctButtonData;

    IXLabel*            m_pLabelText;
    IXLabel*            m_pLabelCaption;
};


class CXMsgBox : public CXMsgBoxImpl<IXMsgBox, XWindowBase>
{
};
